package com.weixing.mall.provider.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weixing.mall.base.constant.DatePattern;
import com.weixing.mall.base.constant.GlobalConstant;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.provider.api.model.vo.RoleVo;
import com.weixing.mall.provider.api.service.SysUserRpcService;
import com.weixing.mall.provider.mapper.FrontShipperRpoertMapper;
import com.weixing.mall.provider.model.domain.Order;
import com.weixing.mall.provider.model.query.FrontShipperReprotQuery;
import com.weixing.mall.provider.model.vo.report.FrontShipperReprot;
import com.weixing.mall.provider.service.IFrontShipperReprotService;
import com.weixing.mall.provider.service.IOrderService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: mall-master
 * @description: 发货部前端报表实现类
 * @author: wangfang
 * @create: 2021-11-10 08:14
 **/
@Service
public class FrontShipperReprotServiceImpl  implements IFrontShipperReprotService {

    @Autowired
    private FrontShipperRpoertMapper  reportMapper;
    @Autowired
    private IOrderService orderService;
    @Autowired
    private SysUserRpcService sysUserRpcService;


    @Override
    public IPage<FrontShipperReprot> dayRepot(IPage page,  FrontShipperReprotQuery frontShipperReprotQuery) {

        return reportMapper.dayRepot(page,frontShipperReprotQuery);
    }

    @Override
    public IPage<FrontShipperReprot> monthRepot(IPage page,  FrontShipperReprotQuery frontShipperReprotQuery) {
        return reportMapper.monthRepot(page,frontShipperReprotQuery);
    }

    @Override
    public Map<String, Object> total(Long uid) {
        Map<String,Object> result=new HashMap<>();
        String day= DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN);
        String month= DateUtil.format(new Date(),"yyyy-MM");
        result.put("day", reportMapper.getDay(uid,day));
        result.put("month", reportMapper.getMonth(uid,month));
        return result;
    }

    @Override
    public FrontShipperReprot dayRepotTotal( FrontShipperReprotQuery frontShipperReprotQuery) {
        return reportMapper.dayRepotTotal(frontShipperReprotQuery);
    }

    @Override
    public FrontShipperReprot monthRepotTotal( FrontShipperReprotQuery frontShipperReprotQuery) {
        return reportMapper.monthRepotTotal(frontShipperReprotQuery);
    }

    @Override
    public Long getShippId(SysAuth sysAuth) {
        List<RoleVo> list = sysUserRpcService.getRoleById(sysAuth.getUid()).getData();
        for (RoleVo vo : list) {
            if (vo.getRoleCode().equals(GlobalConstant.RoleCode.SHIPPING)) {
                    return sysAuth.getUid();
            }
        }
        return null;
    }


}
